﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports BusinessRule.IBusiness
Imports DatabaseAccess.IDAL
Imports System.Data
Imports BusinessRule.Common
Imports DatabaseAccess.DALFactory
Imports External.APICalling
Imports BusinessRule.DTO

Public Class uMESCheckPointManageBusiness
    Implements uMESCheckPointManageIBusiness
    Private dal As IOracleDAL = uMESDalContext.instance.GetDalObject()

    ''' <summary>
    ''' 根据零件图号查询其工艺路线中的工序
    ''' </summary>
    ''' <returns></returns>
    Private Function GetSpecNameByProduct(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetSpecNameByProduct
        Dim oResult As New uMESProcessResult
        Try
            Dim strSQL, strProductName, strProductRev As String
            strProductName = ""
            If QueryCondition.Keys.Contains("ProductName") = True Then
                strProductName = QueryCondition("ProductName").ToString()
            End If
            strProductRev = ""
            If QueryCondition.Keys.Contains("ProductRev") = True Then
                strProductRev = QueryCondition("ProductRev").ToString()
            End If

            strSQL = "SELECT Specname, (Specname || ':' || SpecRevision) AS SpecFullname" & vbCrLf & _
                     "FROM " & vbCrLf & _
                     "(" & vbCrLf & _
                     "SELECT Specbase.Specname, Workflowstep.Sequence, Spec.SpecRevision" & vbCrLf & _
                     "FROM Product" & vbCrLf & _
                     "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                     "INNER JOIN Workflow ON Workflow.Workflowid = Product.Workflowid" & vbCrLf & _
                     "INNER JOIN Workflowstep ON Workflow.Workflowid = Workflowstep.Workflowid" & vbCrLf & _
                     "INNER JOIN Spec ON Workflowstep.Specid = Spec.Specid" & vbCrLf & _
                     "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
                     "WHERE Productbase.Productname = '" & strProductName & "' AND Product.Workflowbaseid = '0000000000000000' " & vbCrLf & _
                     "AND Workflowstep.Specbaseid =  '0000000000000000'" & vbCrLf & _
                     "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                     "OR  (Product.Productrevision = '" & strProductRev & "' ))" & vbCrLf & _
                     "UNION " & vbCrLf & _
                     "SELECT Specbase.Specname, Workflowstep.Sequence, Spec.SpecRevision" & vbCrLf & _
                     "FROM Product" & vbCrLf & _
                     "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                     "INNER JOIN Workflowbase ON Workflowbase.Workflowbaseid = Product.Workflowbaseid" & vbCrLf & _
                     "INNER JOIN Workflowstep ON Workflowbase.Revofrcdid = Workflowstep.Workflowid" & vbCrLf & _
                     "INNER JOIN Spec ON Workflowstep.Specid = Spec.Specid" & vbCrLf & _
                     "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
                     "WHERE Productbase.Productname = '" & strProductName & "' AND Product.Workflowid = '0000000000000000' " & vbCrLf & _
                     "AND Workflowstep.Specbaseid =  '0000000000000000'" & vbCrLf & _
                     "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                     "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
                     "UNION " & vbCrLf & _
                     "SELECT Specbase.Specname, Workflowstep.Sequence, Spec.SpecRevision" & vbCrLf & _
                     "FROM Product" & vbCrLf & _
                     "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                     "INNER JOIN Workflow ON Workflow.Workflowid = Product.Workflowid" & vbCrLf & _
                     "INNER JOIN Workflowstep ON Workflow.Workflowid = Workflowstep.Workflowid" & vbCrLf & _
                     "INNER JOIN Specbase ON Specbase.Specbaseid = Workflowstep.Specbaseid" & vbCrLf & _
                     "INNER JOIN Spec ON Specbase.Revofrcdid = Spec.Specid" & vbCrLf & _
                     "WHERE Productbase.Productname = '" & strProductName & "' AND Product.Workflowbaseid = '0000000000000000' " & vbCrLf & _
                     "AND Workflowstep.Specid =  '0000000000000000'" & vbCrLf & _
                     "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                     "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
                     "UNION " & vbCrLf & _
                     "SELECT Specbase.Specname, Workflowstep.Sequence, Spec.SpecRevision" & vbCrLf & _
                     "FROM Product" & vbCrLf & _
                     "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                     "INNER JOIN Workflowbase ON Workflowbase.Workflowbaseid = Product.Workflowbaseid" & vbCrLf & _
                     "INNER JOIN Workflowstep ON Workflowbase.Revofrcdid = Workflowstep.Workflowid" & vbCrLf & _
                     "INNER JOIN Specbase ON Specbase.Specbaseid = Workflowstep.Specbaseid" & vbCrLf & _
                      "INNER JOIN Spec ON Specbase.Revofrcdid = Spec.Specid" & vbCrLf & _
                     "WHERE Productbase.Productname = '" & strProductName & "' AND Product.Workflowid = '0000000000000000' " & vbCrLf & _
                     "AND Workflowstep.Specid =  '0000000000000000'" & vbCrLf & _
                     "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                     "OR  (Product.Productrevision = '" & strProductRev & "' ))" & vbCrLf & _
                     ") Cinfo" & vbCrLf & _
                     "ORDER BY Sequence" & vbCrLf

            Dim dtMain As DataTable = dal.GetSpecNameByProduct(strSQL)
            oResult.DBTable = dtMain
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    ''' <summary>
    ''' 获取资料表的检验项信息
    ''' </summary>
    ''' <param name="QueryCondition"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetStepCheckPointInfo(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetStepCheckPointInfo
        Dim oResult As New uMESProcessResult
        Try
            Dim strSQL, strProductName, strProductRev, strSpecName, strSpecRev As String
            strProductName = ""
            If QueryCondition.Keys.Contains("ProductName") = True Then
                strProductName = QueryCondition("ProductName").ToString()
            End If
            strProductRev = ""
            If QueryCondition.Keys.Contains("ProductRev") = True Then
                strProductRev = QueryCondition("ProductRev").ToString()
            End If
            strSpecName = ""
            If QueryCondition.Keys.Contains("SpecName") = True Then
                strSpecName = QueryCondition("SpecName").ToString()
            End If
            strSpecRev = ""
            If QueryCondition.Keys.Contains("SpecRev") = True Then
                strSpecRev = QueryCondition("SpecRev").ToString()
            End If

            strSQL =
                <string>
                    SELECT PB.PRODUCTNAME,
                        P.PRODUCTREVISION,
                        SB.SPECNAME,
                        S.SPECREVISION,
                        SC.NAME,sc.productid,sc.specid,sc.workflowstepid,sc.inputnum,
                        SC.CHECKPOINTNOTE,
                        decode(SC.CHECKINPUTTYPE,'1','标准','2','临时',CHECKINPUTTYPE) CHECKINPUTTYPE,
                        decode(SC.CHECKTYPE, '1','专用','2','共用',CHECKTYPE) CHECKTYPE,
                        decode(SC.KEYCHECK, '1','是','0','否',KEYCHECK) KEYCHECK,
                        decode(SC.MEOPCHECK, '1','是','0','否',MEOPCHECK) MEOPCHECK,
                        decode(SC.QUALITYCHECK,  '1','是','0','否',QUALITYCHECK) QUALITYCHECK,
                        SC.INTIME
                    FROM PRODUCT P
                    INNER JOIN PRODUCTBASE PB
                        ON P.PRODUCTBASEID = PB.PRODUCTBASEID
                    INNER JOIN STEPCHECKPOINT SC
                        ON P.PRODUCTID = SC.PRODUCTID
                    INNER JOIN SPEC S
                        ON SC.SPECID = S.SPECID
                    INNER JOIN SPECBASE SB
                        ON (S.SPECBASEID = SB.SPECBASEID OR
                        S.SPECID = SB.REVOFRCDID)
            </string>
            strSQL += String.Format(" where PRODUCTNAME='{0}' and PRODUCTREVISION ='{1}' and SPECNAME='{2}' and SPECREVISION='{3}' ", strProductName, strProductRev, strSpecName, strSpecRev)
            Dim dtMain As DataTable = dal.GetCheckPointGroupInfo(strSQL)
            oResult.DBTable = dtMain
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    ''' <summary>
    ''' add by yuxj,删除工序检测项
    ''' </summary>
    ''' <param name="productid"></param>
    ''' <param name="specid"></param>
    ''' <param name="name"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function DeleteStepCheckinfo(ByVal productid As String, ByVal specid As String, ByVal name As String) As Boolean Implements uMESCheckPointManageIBusiness.DeleteStepCheckinfo
        DeleteStepCheckinfo = False
        Dim strSQL As String = String.Format("delete from STEPCHECKPOINT sc WHERE sc.productid='{0}' AND sc.specid='{1}' AND sc.name='{2}' ", productid, specid, name)
        dal.ExecuteSql(strSQL)
        DeleteStepCheckinfo = True
    End Function


    ''' <summary>
    ''' 根据零件图号和工序获取检测项组信息
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetCheckPointGroupInfo(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetCheckPointGroupInfo
        Dim oResult As New uMESProcessResult
        Try
            Dim strSQL, strProductName, strProductRev, strSpecName, strSpecRev As String
            strProductName = ""
            If QueryCondition.Keys.Contains("ProductName") = True Then
                strProductName = QueryCondition("ProductName").ToString()
            End If
            strProductRev = ""
            If QueryCondition.Keys.Contains("ProductRev") = True Then
                strProductRev = QueryCondition("ProductRev").ToString()
            End If
            strSpecName = ""
            If QueryCondition.Keys.Contains("SpecName") = True Then
                strSpecName = QueryCondition("SpecName").ToString()
            End If
            strSpecRev = ""
            If QueryCondition.Keys.Contains("SpecRev") = True Then
                strSpecRev = QueryCondition("SpecRev").ToString()
            End If
            strSQL = "SELECT Checkpointgroup.Checkpointgroupname, Productbase.Productname, Product.Productrevision, Specbase.Specname," & vbCrLf & _
                    "       Spec.Specrevision, DECODE(Checkpointgroup.Grouptype, 1,'标准', 2, '临时') AS Grouptype, Checkpointgroup.Notes " & vbCrLf & _
                    ",(CASE WHEN (SELECT cp.checkpointgroupid FROM checkpointresultdetail cprd" & vbCrLf & _
                    "LEFT JOIN checkpoints cp ON cp.checkpointsid = cprd.checkpoints" & vbCrLf & _
                    "WHERE cp.checkpointgroupid = checkpointgroup.checkpointgroupid" & vbCrLf & _
                    "GROUP BY cp.checkpointgroupid) IS NULL THEN 0 ELSE 1 END) AS IsUse" & vbCrLf & _
                    ",Checkpointgroup.Description" & vbCrLf & _
                    "FROM Checkpointgroup" & vbCrLf & _
                    "INNER JOIN Product ON Checkpointgroup.Productid = Product.Productid" & vbCrLf & _
                    "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                    "INNER JOIN Spec ON Checkpointgroup.Specid = Spec.Specid" & vbCrLf & _
                    "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid " & vbCrLf & _
                    "WHERE Productbase.Productname = '" & strProductName & "'" & vbCrLf & _
                    "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                    "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
                    "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
                    "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
                    "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf

            Dim dtMain As DataTable = dal.GetCheckPointGroupInfo(strSQL)
            oResult.DBTable = dtMain
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    ''' <summary>
    ''' 根据检测项组名获取检测项组信息
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetCheckPointInfo(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetCheckPointInfo
        Dim oResult As New uMESProcessResult
        Try
            Dim strSQL, strCheckPointGroupName As String
            strCheckPointGroupName = ""
            If QueryCondition.Keys.Contains("Checkpointgroupname") = True Then
                strCheckPointGroupName = QueryCondition("Checkpointgroupname").ToString()
            End If

            strSQL = "SELECT Checkpointgroup.Checkpointgroupname, Checkpoints.Checkpointnote, Checkpoints.Inputnum, '' AS CheckPointDisp,Checkpoints.description " & vbCrLf & _
                    "FROM Checkpointgroup" & vbCrLf & _
                    "LEFT JOIN Checkpointgroupcheckpoints ON Checkpointgroupcheckpoints.Checkpointgroupid = Checkpointgroup.Checkpointgroupid" & vbCrLf & _
                    "INNER JOIN Checkpoints ON Checkpointgroupcheckpoints.Checkpointsid = Checkpoints.Checkpointsid" & vbCrLf & _
                    "WHERE Checkpointgroup.Checkpointgroupname = '" & strCheckPointGroupName & "'" & vbCrLf

            Dim dtMain As DataTable = dal.GetCheckPointInfo(strSQL)
            oResult.DBTable = dtMain
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    ''' <summary>
    ''' 创建检测项组
    ''' </summary>
    ''' <param name="oCheckPointInfo">检测项组创建所需的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CreateCheckPointGroup(ByVal oCheckPointInfo As CheckPointInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.CreateCheckPointGroup
        CreateCheckPointGroup = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointGroupMaintDoc"
            strTxnName = "CheckPointGroupMaint"
            strEventName = "New"
            strSubentityListName = "CheckPoints"

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Name"
            dataEntity.ClientDataValue = oCheckPointInfo.Name
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Description"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointGroupName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Notes"
            dataEntity.ClientDataValue = oCheckPointInfo.Notes
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strProdName As String = oCheckPointInfo.ProductName
            Dim strProdRev As String = oCheckPointInfo.ProductRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Product"
            dataEntity.ClientDataValue = strProdName

            If strProdRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strProdRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strProdRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strSpecName As String = oCheckPointInfo.SpecName
            Dim strSpecRev As String = oCheckPointInfo.SpecRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Spec"
            dataEntity.ClientDataValue = strSpecName
            If strSpecRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strSpecRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strSpecRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "GroupType"
            dataEntity.ClientDataValue = oCheckPointInfo.GroupType
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "SubmitEmployee"
            dataEntity.ClientDataValue = oCheckPointInfo.SubmitEmployee
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "SubmitDate"
            dataEntity.ClientDataValue = oCheckPointInfo.SubmitDate
            m_DataList.Add(dataEntity)

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsList

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPointNote"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPointNote").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputNum"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputNum").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "Description"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("Description").ToString
                        m_Child.Add(stepEntity)

                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.CreateModelHasSubentityList(strTxnDocName, strTxnName, strEventName, m_DataList, strSubentityListName, m_ChildList, strInfo)

            If success = True Then
                CreateCheckPointGroup = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function

#Region "2014-11-27 苗利刚添加 修改检测项组==============================================="
    ''' <summary>
    ''' 修改检测项组
    ''' </summary>
    ''' <param name="strName">原检测项组名称</param>
    ''' <param name="intCount">SubentityListCount_Old</param>
    ''' <param name="oCheckPointInfo">检测项组创建所需的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateCheckPointGroup(ByVal strName As String, ByVal intCount As Integer, ByVal oCheckPointInfo As CheckPointInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.UpdateCheckPointGroup
        UpdateCheckPointGroup = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointGroupMaintDoc"
            strTxnName = "CheckPointGroupMaint"
            strEventName = "New"
            strSubentityListName = "CheckPoints"

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Description"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointGroupName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Notes"
            dataEntity.ClientDataValue = oCheckPointInfo.Notes
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strProdName As String = oCheckPointInfo.ProductName
            Dim strProdRev As String = oCheckPointInfo.ProductRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Product"
            dataEntity.ClientDataValue = strProdName

            If strProdRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strProdRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strProdRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strSpecName As String = oCheckPointInfo.SpecName
            Dim strSpecRev As String = oCheckPointInfo.SpecRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Spec"
            dataEntity.ClientDataValue = strSpecName
            If strSpecRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strSpecRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strSpecRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "GroupType"
            dataEntity.ClientDataValue = oCheckPointInfo.GroupType
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "SubmitEmployee"
            dataEntity.ClientDataValue = oCheckPointInfo.SubmitEmployee
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "SubmitDate"
            dataEntity.ClientDataValue = oCheckPointInfo.SubmitDate
            m_DataList.Add(dataEntity)

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsList

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPointNote"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPointNote").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputNum"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputNum").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "Description"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("Description").ToString
                        m_Child.Add(stepEntity)

                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.UpdateModelHasSubentityList(strTxnDocName, strTxnName, strName, "", "NDO", m_DataList, strSubentityListName, m_ChildList, intCount, strInfo)

            If success = True Then
                UpdateCheckPointGroup = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function
#End Region

    ''' <summary>
    ''' 录入检测项界面获取检测项信息
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetCheckPointInfoForCheck(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetCheckPointInfoForCheck
        Dim oResult As New uMESProcessResult
        Try
            Dim dtCheckPointInfo As New DataTable
            dtCheckPointInfo = GetCheckPointInfoByProductSpec(QueryCondition).Copy

            Dim dtContainerAllChild As New DataTable
            dtContainerAllChild = GetProductNoByContainer(QueryCondition).DBTable.Copy

            Dim dtContainerChildTemp As New DataTable
            dtContainerChildTemp = dtContainerAllChild.Copy()

            Dim strSQL, strContainerName, strProductName, strProductRev, strSpecName, strSpecRev, strGrouptype As String
            strContainerName = ""
            If QueryCondition.Keys.Contains("ContainerName") = True Then
                strContainerName = QueryCondition("ContainerName").ToString()
            End If
            strProductName = ""
            If QueryCondition.Keys.Contains("ProductName") = True Then
                strProductName = QueryCondition("ProductName").ToString()
            End If
            strProductRev = ""
            If QueryCondition.Keys.Contains("ProductRev") = True Then
                strProductRev = QueryCondition("ProductRev").ToString()
            End If
            strSpecName = ""
            If QueryCondition.Keys.Contains("SpecName") = True Then
                strSpecName = QueryCondition("SpecName").ToString()
            End If
            strSpecRev = ""
            If QueryCondition.Keys.Contains("SpecRev") = True Then
                strSpecRev = QueryCondition("SpecRev").ToString()
            End If
            strGrouptype = ""
            If QueryCondition.Keys.Contains("GroupType") = True Then
                strGrouptype = QueryCondition("GroupType").ToString()
            End If
            Dim strGroupName As String = ""
            If QueryCondition.Keys.Contains("GroupName") = True Then
                strGroupName = QueryCondition("GroupName").ToString
            End If

            strSQL = "SELECT DISTINCT Checkpoints.Checkpointsid,  Containerchilds.Containername AS Productno, " & vbCrLf & _
            "        Checkpoints.Checkpointnote, Checkpoints.Inputnum, '' AS CheckPointDisp, CheckPointResult.Checkpointresultname, " & vbCrLf & _
            "        NVL(COUNT(CheckPointResultDetail.Checkpointresultdetailid),0) AS ResultNum" & vbCrLf & _
            "FROM Checkpointgroup" & vbCrLf
            '"INNER JOIN " & vbCrLf & _
            '"(" & vbCrLf & _
            '"SELECT Checkpointgroup.Productid, Checkpointgroup.Specid, Checkpointgroup.Grouptype, MAX(Checkpointgroup.Submitdate) AS Submitdate" & vbCrLf & _
            '"FROM Checkpointgroup" & vbCrLf & _
            '"GROUP BY  Checkpointgroup.Productid, Checkpointgroup.Specid, Checkpointgroup.Grouptype" & vbCrLf & _
            '") CMax" & vbCrLf & _
            '"ON Checkpointgroup.Productid =  CMax.Productid" & vbCrLf & _
            '"AND Checkpointgroup.Specid =  CMax.Specid" & vbCrLf & _
            '"AND Checkpointgroup.Submitdate = CMax.Submitdate" & vbCrLf & _
            strSQL += "INNER JOIN Product ON Checkpointgroup.Productid = Product.Productid" & vbCrLf & _
            "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
            "INNER JOIN Spec ON Checkpointgroup.Specid = Spec.Specid" & vbCrLf & _
            "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
            "LEFT JOIN Checkpointgroupcheckpoints ON Checkpointgroupcheckpoints.Checkpointgroupid = Checkpointgroup.Checkpointgroupid" & vbCrLf & _
            "INNER JOIN Checkpoints ON Checkpointgroupcheckpoints.Checkpointsid = Checkpoints.Checkpointsid" & vbCrLf & _
            "INNER JOIN Container ON Container.Productid = Checkpointgroup.Productid " & vbCrLf & _
            "LEFT JOIN Container Containerchilds ON Container.Containerid = Containerchilds.Parentcontainerid  " & vbCrLf
            '"LEFT JOIN CheckPointResult ON Container.Containerid = CheckPointResult.Containerid" & vbCrLf & _
            '"AND CheckPointResult.Specid = Checkpointgroup.Specid" & vbCrLf & _
            strSQL += "LEFT JOIN CheckPointResult ON CheckPointResult.Checkpointgroupid = Checkpointgroup.Checkpointgroupid" & vbCrLf & _
                "LEFT JOIN Checkpointresultcheckpointresu ON Checkpointresultcheckpointresu.Checkpointresultid = CheckPointResult.Checkpointresultid" & vbCrLf & _
            "LEFT JOIN CheckPointResultDetail ON CheckPointResultDetail.Checkpointresultdetailid = Checkpointresultcheckpointresu.Checkpointresultdetailid" & vbCrLf & _
            "AND CheckPointResultDetail.Productno =  Containerchilds.Containername" & vbCrLf & _
            "WHERE Container.Containername ='" & strContainerName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
            "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
            "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
            "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf & _
            "AND Checkpointgroup.GroupType = '" & strGrouptype & "'" & vbCrLf & _
            "AND Checkpointgroup.CheckpointgroupName = '" & strGroupName & "'" & vbCrLf & _
            "GROUP BY Checkpoints.Checkpointsid,  Containerchilds.Containername, Checkpoints.Checkpointnote, Checkpoints.Inputnum, " & vbCrLf & _
            "CheckPointResult.Checkpointresultid, CheckPointResult.Checkpointresultname " & vbCrLf & _
            "ORDER BY Containerchilds.Containername, Checkpoints.Checkpointsid" & vbCrLf

            Dim dtMain As DataTable = dal.GetCheckPointInfoForCheck(strSQL)

            Dim strCheckpointresultname As String = ""
            If dtMain.Rows.Count > 0 Then
                If dtMain.Rows(0).IsNull("Checkpointresultname") = False Then
                    strCheckpointresultname = dtMain.Rows(0).Item("Checkpointresultname")
                End If
            End If

            strSQL = "SELECT CheckPointResultDetail.Checkpoints AS Checkpointsid, " & vbCrLf & _
            "        CheckPointResultDetail.Productno, CheckPointResultDetail.Inputindex,  CheckPointResultDetail.Workerresultinfo," & vbCrLf & _
            "       Employee.Fullname AS WorkerFullName, Replace(TO_CHAR(CheckPointResultDetail.Submitworkerdate,'RRRR-MM-DD HH24:MI:SS'), ' ','T') AS Submitworkerdate, CheckPointResultDetail.Checkerresultinfo, " & vbCrLf & _
            "       Checker.Fullname AS CheckerFullName, Replace(TO_CHAR(CheckPointResultDetail.Submitcheckerdate,'RRRR-MM-DD HH24:MI:SS'), ' ','T') AS Submitcheckerdate, '' AS EditType," & vbCrLf & _
            "       Employee.Employeename AS WorkerName, Checker.Employeename AS CheckerName, CheckPointResultDetail.Workerdocurl, CheckPointResultDetail.Checkerdocurl" & vbCrLf & _
            "FROM Container" & vbCrLf & _
            "INNER JOIN CheckPointResult ON Container.Containerid = CheckPointResult.Containerid" & vbCrLf & _
            "INNER JOIN Checkpointresultcheckpointresu ON Checkpointresultcheckpointresu.Checkpointresultid = CheckPointResult.Checkpointresultid" & vbCrLf & _
            "INNER JOIN CheckPointResultDetail ON CheckPointResultDetail.Checkpointresultdetailid = Checkpointresultcheckpointresu.Checkpointresultdetailid" & vbCrLf & _
            "INNER JOIN Product ON Container.Productid = Product.Productid" & vbCrLf & _
            "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
            "INNER JOIN Spec ON CheckPointResult.Specid = Spec.Specid" & vbCrLf & _
            "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
            "LEFT JOIN Employee ON Employee.Employeeid =  CheckPointResultDetail.Submitworkerid " & vbCrLf & _
            "LEFT JOIN Employee Checker ON Checker.Employeeid =  CheckPointResultDetail.Submitcheckerid" & vbCrLf & _
            "INNER JOIN Checkpoints ON Checkpoints.Checkpointsid = CheckPointResultDetail.Checkpoints " & vbCrLf & _
            "INNER JOIN CheckPointGroupCheckPoints ON CheckPointGroupCheckPoints.Checkpointsid = Checkpoints.Checkpointsid " & vbCrLf & _
            "INNER JOIN Checkpointgroup ON Checkpointgroup.Checkpointgroupid = CheckPointGroupCheckPoints.Checkpointgroupid " & vbCrLf & _
            "WHERE Container.Containername ='" & strContainerName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
            "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
            "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
            "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf & _
            "AND CheckPointResult.Checkpointresultname = '" & strCheckpointresultname & "'" & vbCrLf & _
            "AND Checkpointgroup.CheckpointgroupName = '" & strGroupName & "'" & vbCrLf

            Dim dtResult As DataTable = dal.GetCheckPointResult(strSQL)

            If dtResult.Rows.Count > 0 And dtContainerChildTemp.Rows.Count > 0 Then
                For i = dtContainerChildTemp.Rows.Count - 1 To 0 Step -1
                    If dtContainerChildTemp.Rows(i).IsNull("Productno") = False Then
                        Dim strProductNo As String
                        strProductNo = dtContainerChildTemp.Rows(i).Item("Productno")
                        If dtResult.Select("Productno ='" & strProductNo & "'").Length > 0 Then
                            dtContainerChildTemp.Rows.RemoveAt(i)
                        End If
                    End If
                Next
            End If

            dtMain.Columns.Add("GID")
            dtResult.Columns.Add("GID")
            dtResult.Columns.Add("PGID")

            For Each row As DataRow In dtMain.Rows
                row("GID") = Guid.NewGuid().ToString().Trim()
            Next

            For Each row As DataRow In dtResult.Rows
                row("GID") = Guid.NewGuid().ToString().Trim()
            Next

            For i = 0 To dtMain.Rows.Count - 1
                Dim strCheckpointsid, strProductNo, strInputnum As String
                strCheckpointsid = dtMain.Rows(i).Item("Checkpointsid")

                If dtMain.Rows(i).IsNull("ProductNo") = False Then
                    strProductNo = dtMain.Rows(i).Item("ProductNo")
                Else
                    strProductNo = ""
                End If

                strInputnum = dtMain.Rows(i).Item("Inputnum")

                Dim drs As DataRow()
                'drs = dtResult.Select("Checkpointsid = '" & strCheckpointsid & "' AND ProductNo = '" & strProductNo & "'")
                drs = dtResult.Select("Checkpointsid = '" & strCheckpointsid & "'")

                If drs.Length = 0 Then
                    If IsNumeric(strInputnum) = True Then
                        Dim intInputnum As Integer
                        intInputnum = CInt(strInputnum)
                        If intInputnum > 0 Then
                            For j = 1 To intInputnum
                                Dim dr As DataRow
                                dr = dtResult.NewRow
                                dr("Checkpointsid") = strCheckpointsid
                                dr("ProductNo") = strProductNo
                                dr("Inputindex") = j
                                dr("EditType") = "add"
                                dr("PGID") = dtMain.Rows(i)("GID").ToString().Trim()
                                dtResult.Rows.Add(dr)
                            Next
                        End If
                    End If
                End If
            Next

            Dim ds As New DataSet
            ds.Tables.Add(dtMain.Copy())
            ds.Tables(0).TableName = "dtMain"
            ds.Tables.Add(dtResult.Copy())
            ds.Tables(1).TableName = "dtResult"
            ds.Tables.Add(dtContainerAllChild.Copy())
            ds.Tables(2).TableName = "dtContainerAllChild"
            ds.Tables.Add(dtCheckPointInfo.Copy())
            ds.Tables(3).TableName = "dtCheckPointInfo"
            ds.Tables.Add(dtContainerChildTemp.Copy())
            ds.Tables(4).TableName = "dtContainerChildTemp"

            'Dim parentColunms = New DataColumn(1) {ds.Tables(0).Columns("Checkpointsid"), ds.Tables(0).Columns("Productno")}
            'Dim childColunms = New DataColumn(1) {ds.Tables(1).Columns("Checkpointsid"), ds.Tables(1).Columns("Productno")}

            Dim parentColunms = New DataColumn(0) {ds.Tables(0).Columns("GID")}
            Dim childColunms = New DataColumn(0) {ds.Tables(1).Columns("PGID")}

            ds.Relations.Add("rs0", parentColunms, childColunms)

            oResult.DBDataSet = ds
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    Public Function GetCheckPointGroupByProductAndSpec(ByVal para As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetCheckPointGroupByProductAndSpec
        Dim strProductName As String = ""
        Dim strProductRev As String = ""
        If para.Keys.Contains("ProductName") Then
            strProductName = para("ProductName").ToString
            strProductRev = para("ProductRev").ToString
        End If

        Dim strSpecName As String = ""
        Dim strSpecRev As String = ""

        If para.Keys.Contains("SpecName") Then
            strSpecName = para("SpecName").ToString
            strSpecRev = para("SpecRev").ToString
        End If

        Dim strGroupType As String = ""
        If para.Keys.Contains("GroupType") Then
            strGroupType = para("GroupType").ToString
        End If

        Dim strQuery As String = "SELECT cpg.checkpointgroupname,cpg.description" & vbCrLf & _
                                "FROM checkpointgroup cpg" & vbCrLf & _
                                "LEFT JOIN product p ON p.productid = cpg.productid" & vbCrLf & _
                                "LEFT JOIN productbase pb ON pb.productbaseid = p.productbaseid" & vbCrLf & _
                                "LEFT JOIN spec s ON s.specid = cpg.specid" & vbCrLf & _
                                "LEFT JOIN specbase sb ON sb.specbaseid = s.specbaseid" & vbCrLf & _
                                "WHERE 1 = 1" & vbCrLf & _
                                "AND cpg.grouptype = " & strGroupType & vbCrLf & _
                                "AND pb.productname = '" & strProductName & "'" & vbCrLf & _
                                "AND p.productrevision = '" & strProductRev & "'" & vbCrLf & _
                                "AND sb.specname = '" & strSpecName & "'" & vbCrLf & _
                                "AND s.specrevision = '" & strSpecRev & "'" & vbCrLf

        Dim result As New uMESProcessResult

        Try
            Dim DT As DataTable = dal.GetCheckPointInfoForCheck(strQuery)
            result.Result = True
            result.DBTable = DT
        Catch ex As Exception
            result.Result = False
            result.Message = ex.Message
        End Try

        Return result
    End Function

    ''' <summary>
    ''' 创建检测项录入结果(工人)
    ''' </summary>
    ''' <param name="oCheckPointInfo">检测项录入的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CreateCheckPointResultByWorker(ByVal oCheckPointInfo As CheckPointResultInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.CreateCheckPointResultByWorker
        CreateCheckPointResultByWorker = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointResultMaintDoc"
            strTxnName = "CheckPointResultMaint"
            strEventName = "New"
            strSubentityListName = "CheckPointResultDetail"

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Name"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointResultName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Container"
            dataEntity.ClientDataValue = oCheckPointInfo.ContainerName
            dataEntity.ClientOtherValue = ""
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "CheckPointGroup"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointGroupName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strProdName As String = oCheckPointInfo.ProductName
            Dim strProdRev As String = oCheckPointInfo.ProductRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Product"
            dataEntity.ClientDataValue = strProdName

            If strProdRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strProdRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strProdRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strSpecName As String = oCheckPointInfo.SpecName
            Dim strSpecRev As String = oCheckPointInfo.SpecRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Spec"
            dataEntity.ClientDataValue = strSpecName
            If strSpecRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strSpecRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strSpecRev
            End If
            m_DataList.Add(dataEntity)

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsResultDetail

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "ProductNo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("ProductNo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPoints"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPoints").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputIndex"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputIndex").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "WorkerResultInfo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerResultInfo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                        stepEntity.ClientDataName = "SubmitWorker"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorker").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "SubmitWorkerDate"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorkerDate").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "WorkerDocUrl"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerDocUrl").ToString
                        m_Child.Add(stepEntity)

                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.CreateModelHasSubentityList(strTxnDocName, strTxnName, strEventName, m_DataList, strSubentityListName, m_ChildList, strInfo)

            If success = True Then
                CreateCheckPointResultByWorker = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 更新检测项录入结果(工人)
    ''' </summary>
    ''' <param name="oCheckPointInfo">检测项录入的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateCheckPointResultByWorker(ByVal oCheckPointInfo As CheckPointResultInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.UpdateCheckPointResultByWorker
        UpdateCheckPointResultByWorker = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointResultMaintDoc"
            strTxnName = "CheckPointResultMaint"
            strEventName = "Load"
            strSubentityListName = "CheckPointResultDetail"

            Dim strUpdateName, strUpdateVersion, strUpdateCDOType As String
            strUpdateName = oCheckPointInfo.CheckPointResultName
            strUpdateVersion = ""
            strUpdateCDOType = "NDO"

            Dim intSubentityListCount As Integer
            intSubentityListCount = oCheckPointInfo.SubentityListCount

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsResultDetail

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "ProductNo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("ProductNo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPoints"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPoints").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputIndex"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputIndex").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "WorkerResultInfo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerResultInfo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                        stepEntity.ClientDataName = "SubmitWorker"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorker").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "SubmitWorkerDate"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorkerDate").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "WorkerDocUrl"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerDocUrl").ToString
                        m_Child.Add(stepEntity)

                        If dtChildList.Rows(i).IsNull("CheckerResultInfo") = False Then
                            If dtChildList.Rows(i).Item("CheckerResultInfo") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "CheckerResultInfo"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerResultInfo").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        If dtChildList.Rows(i).IsNull("SubmitChecker") = False Then
                            If dtChildList.Rows(i).Item("SubmitChecker") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                                stepEntity.ClientDataName = "SubmitChecker"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitChecker").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        If dtChildList.Rows(i).IsNull("SubmitCheckerDate") = False Then
                            If dtChildList.Rows(i).Item("SubmitCheckerDate") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "SubmitCheckerDate"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitCheckerDate").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        If dtChildList.Rows(i).IsNull("CheckerDocUrl") = False Then
                            If dtChildList.Rows(i).Item("CheckerDocUrl") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "CheckerDocUrl"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerDocUrl").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.UpdateModelHasSubentityList(strTxnDocName, strTxnName, strUpdateName, strUpdateVersion, _
                                                            strUpdateCDOType, m_DataList, strSubentityListName, m_ChildList, intSubentityListCount, strInfo)

            If success = True Then
                UpdateCheckPointResultByWorker = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 创建检测项录入结果(检验员)
    ''' </summary>
    ''' <param name="oCheckPointInfo">检测项录入的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function CreateCheckPointResultByChecker(ByVal oCheckPointInfo As CheckPointResultInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.CreateCheckPointResultByChecker
        CreateCheckPointResultByChecker = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointResultMaintDoc"
            strTxnName = "CheckPointResultMaint"
            strEventName = "New"
            strSubentityListName = "CheckPointResultDetail"

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            dataEntity.ClientDataTypeEnum = DataTypeEnum.DataField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Name"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointResultName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.ContainerField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Container"
            dataEntity.ClientDataValue = oCheckPointInfo.ContainerName
            dataEntity.ClientOtherValue = ""
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            dataEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "CheckPointGroup"
            dataEntity.ClientDataValue = oCheckPointInfo.CheckPointGroupName
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strProdName As String = oCheckPointInfo.ProductName
            Dim strProdRev As String = oCheckPointInfo.ProductRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Product"
            dataEntity.ClientDataValue = strProdName

            If strProdRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strProdRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strProdRev
            End If
            m_DataList.Add(dataEntity)

            dataEntity = New ClientAPIEntity
            Dim strSpecName As String = oCheckPointInfo.SpecName
            Dim strSpecRev As String = oCheckPointInfo.SpecRevision

            dataEntity.ClientDataTypeEnum = DataTypeEnum.RevisionedObjectField
            dataEntity.ClientInputTypeEnum = InputTypeEnum.Details
            dataEntity.ClientDataName = "Spec"
            dataEntity.ClientDataValue = strSpecName
            If strSpecRev <> "" Then
                dataEntity.ClientDataIsROR = False
                dataEntity.ClientDataVersion = strSpecRev
            Else
                dataEntity.ClientDataIsROR = True
                dataEntity.ClientDataVersion = strSpecRev
            End If
            m_DataList.Add(dataEntity)

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsResultDetail

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "ProductNo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("ProductNo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPoints"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPoints").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputIndex"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputIndex").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckerResultInfo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerResultInfo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                        stepEntity.ClientDataName = "SubmitChecker"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitChecker").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "SubmitCheckerDate"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitCheckerDate").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckerDocUrl"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerDocUrl").ToString
                        m_Child.Add(stepEntity)


                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.CreateModelHasSubentityList(strTxnDocName, strTxnName, strEventName, m_DataList, strSubentityListName, m_ChildList, strInfo)

            If success = True Then
                CreateCheckPointResultByChecker = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 更新检测项录入结果(检验员)
    ''' </summary>
    ''' <param name="oCheckPointInfo">检测项录入的基础信息</param>
    ''' <param name="result">执行结果</param>
    ''' <param name="message">返回结果信息</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function UpdateCheckPointResultByChecker(ByVal oCheckPointInfo As CheckPointResultInfo, ByRef result As Boolean, ByRef message As String) As Boolean Implements uMESCheckPointManageIBusiness.UpdateCheckPointResultByChecker
        UpdateCheckPointResultByChecker = False
        result = False
        Try
            Dim strInfo As String = ""
            Dim success As Boolean = False
            Dim daServerHost As ServerHostInfo = oCheckPointInfo.ServerHostInfo

            Dim strTxnDocName, strTxnName, strEventName, strSubentityListName As String
            strTxnDocName = "CheckPointResultMaintDoc"
            strTxnName = "CheckPointResultMaint"
            strEventName = "Load"
            strSubentityListName = "CheckPointResultDetail"

            Dim strUpdateName, strUpdateVersion, strUpdateCDOType As String
            strUpdateName = oCheckPointInfo.CheckPointResultName
            strUpdateVersion = ""
            strUpdateCDOType = "NDO"

            Dim intSubentityListCount As Integer
            intSubentityListCount = oCheckPointInfo.SubentityListCount

            Dim m_DataList As New List(Of ClientAPIEntity)

            Dim dataEntity As New ClientAPIEntity

            Dim m_ChildList As New Dictionary(Of String, List(Of ClientAPIEntity))

            Dim dtChildList As DataTable = oCheckPointInfo.CheckPointsResultDetail

            If dtChildList IsNot Nothing Then
                If dtChildList.Rows.Count > 0 Then
                    For i As Integer = 0 To dtChildList.Rows.Count - 1
                        Dim m_Child As New List(Of ClientAPIEntity)
                        Dim stepEntity As New ClientAPIEntity

                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "ProductNo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("ProductNo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckPoints"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckPoints").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "InputIndex"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("InputIndex").ToString
                        m_Child.Add(stepEntity)

                        If dtChildList.Rows(i).IsNull("WorkerResultInfo") = False Then
                            If dtChildList.Rows(i).Item("WorkerResultInfo") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "WorkerResultInfo"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerResultInfo").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If
                        If dtChildList.Rows(i).IsNull("SubmitWorker") = False Then
                            If dtChildList.Rows(i).Item("SubmitWorker") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                                stepEntity.ClientDataName = "SubmitWorker"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorker").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        If dtChildList.Rows(i).IsNull("SubmitWorkerDate") = False Then
                            If dtChildList.Rows(i).Item("SubmitWorkerDate") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "SubmitWorkerDate"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitWorkerDate").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        If dtChildList.Rows(i).IsNull("WorkerDocUrl") = False Then
                            If dtChildList.Rows(i).Item("WorkerDocUrl") <> "" Then
                                stepEntity = New ClientAPIEntity
                                stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                                stepEntity.ClientDataName = "WorkerDocUrl"
                                stepEntity.ClientDataValue = dtChildList.Rows(i).Item("WorkerDocUrl").ToString
                                m_Child.Add(stepEntity)
                            End If
                        End If

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckerResultInfo"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerResultInfo").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.NamedObjectField
                        stepEntity.ClientDataName = "SubmitChecker"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitChecker").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "SubmitCheckerDate"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("SubmitCheckerDate").ToString
                        m_Child.Add(stepEntity)

                        stepEntity = New ClientAPIEntity
                        stepEntity.ClientDataTypeEnum = DataTypeEnum.DataField
                        stepEntity.ClientDataName = "CheckerDocUrl"
                        stepEntity.ClientDataValue = dtChildList.Rows(i).Item("CheckerDocUrl").ToString
                        m_Child.Add(stepEntity)

                        m_ChildList.Add(i.ToString, m_Child)
                    Next
                End If
            End If

            Dim serverUser As String = daServerHost.UserName
            Dim serverPassword As String = daServerHost.Password

            Dim clientData As New CamstarClientAPI(serverUser, serverPassword)
            success = clientData.UpdateModelHasSubentityList(strTxnDocName, strTxnName, strUpdateName, strUpdateVersion, _
                                                            strUpdateCDOType, m_DataList, strSubentityListName, m_ChildList, intSubentityListCount, strInfo)

            If success = True Then
                UpdateCheckPointResultByChecker = True
                result = True
            End If

            message = strInfo
        Catch ex As Exception
            result = False
            message = ex.Message
            Return False
        End Try
    End Function

    ''' <summary>
    ''' 根据零件图号和工序获取检测项组信息
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetCheckPointInfoByProductSpec(ByVal QueryCondition As Dictionary(Of String, String)) As DataTable
        GetCheckPointInfoByProductSpec = New DataTable

        Dim strSQL, strProductName, strProductRev, strSpecName, strSpecRev As String
        strProductName = ""
        If QueryCondition.Keys.Contains("ProductName") = True Then
            strProductName = QueryCondition("ProductName").ToString()
        End If
        strProductRev = ""
        If QueryCondition.Keys.Contains("ProductRev") = True Then
            strProductRev = QueryCondition("ProductRev").ToString()
        End If
        strSpecName = ""
        If QueryCondition.Keys.Contains("SpecName") = True Then
            strSpecName = QueryCondition("SpecName").ToString()
        End If
        strSpecRev = ""
        If QueryCondition.Keys.Contains("SpecRev") = True Then
            strSpecRev = QueryCondition("SpecRev").ToString()
        End If
        Dim strGroupName As String = ""
        If QueryCondition.Keys.Contains("GroupName") Then
            strGroupName = QueryCondition("GroupName").ToString
        End If
        strSQL = "SELECT Checkpointgroup.Checkpointgroupname, Productbase.Productname, Product.Productrevision, Specbase.Specname," & vbCrLf & _
                "       Spec.Specrevision, DECODE(Checkpointgroup.Grouptype, 1,'标准', 2, '临时') AS Grouptype, Checkpoints.Checkpointnote" & vbCrLf & _
                "FROM Checkpointgroup" & vbCrLf
        '"INNER JOIN " & vbCrLf & _
        '"(" & vbCrLf & _
        '"SELECT Checkpointgroup.Productid, Checkpointgroup.Specid, Checkpointgroup.Grouptype, MAX(Checkpointgroup.Submitdate) AS Submitdate" & vbCrLf & _
        '"FROM Checkpointgroup" & vbCrLf & _
        '"GROUP BY  Checkpointgroup.Productid, Checkpointgroup.Specid, Checkpointgroup.Grouptype" & vbCrLf & _
        '") CMax" & vbCrLf & _
        '"ON Checkpointgroup.Productid =  CMax.Productid" & vbCrLf & _
        '"AND Checkpointgroup.Specid =  CMax.Specid" & vbCrLf & _
        '"AND Checkpointgroup.Submitdate = CMax.Submitdate" & vbCrLf & _
        strSQL += "INNER JOIN Product ON Checkpointgroup.Productid = Product.Productid" & vbCrLf & _
                "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
                "INNER JOIN Spec ON Checkpointgroup.Specid = Spec.Specid" & vbCrLf & _
                "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
                "LEFT JOIN Checkpointgroupcheckpoints ON Checkpointgroupcheckpoints.Checkpointgroupid = Checkpointgroup.Checkpointgroupid" & vbCrLf & _
                "INNER JOIN Checkpoints ON Checkpointgroupcheckpoints.Checkpointsid = Checkpoints.Checkpointsid " & vbCrLf & _
                "WHERE Productbase.Productname = '" & strProductName & "'" & vbCrLf & _
                "AND Checkpointgroup.CheckpointgroupName = '" & strGroupName & "'" & vbCrLf & _
                "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
                "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
                "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
                "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
                "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf

        Dim dtMain As DataTable = dal.GetCheckPointGroupInfo(strSQL)
        GetCheckPointInfoByProductSpec = dtMain
    End Function

    ''' <summary>
    ''' 根据批次获取零件序号
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetProductNoByContainer(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetProductNoByContainer
        Dim oResult As New uMESProcessResult

        Try
            Dim strSQL, strContainerName As String
            strContainerName = ""
            If QueryCondition.Keys.Contains("ContainerName") = True Then
                strContainerName = QueryCondition("ContainerName").ToString()
            End If

            strSQL = "SELECT Container.Containername, ContainerChilds.Containername AS Productno,replace(ContainerChilds.Containername,Container.Containername || '-','') AS ProductNoDesc" & vbCrLf & _
                    "FROM Container" & vbCrLf & _
                    "INNER JOIN Container ContainerChilds ON ContainerChilds.Parentcontainerid = Container.Containerid " & vbCrLf & _
                    "WHERE Container.Containername = '" & strContainerName & "' AND ContainerChilds.Qty > 0 AND ContainerChilds.Status =1 AND Container.Parentcontainerid IS NULL" & vbCrLf & _
                    "ORDER BY ContainerChilds.Containername " & vbCrLf

            Dim dtMain As DataTable = dal.GetProductNoByContainer(strSQL)
            oResult.DBTable = dtMain
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    ''' <summary>
    ''' 录入检测项界面获取检测项信息
    ''' </summary>
    ''' <returns></returns>
    ''' 
    Private Function GetCheckPointInfoView(ByVal QueryCondition As Dictionary(Of String, String)) As uMESProcessResult Implements uMESCheckPointManageIBusiness.GetCheckPointInfoView
        Dim oResult As New uMESProcessResult
        Try
            Dim strSQL, strContainerName, strProductName, strProductRev, strSpecName, strSpecRev As String
            strContainerName = ""
            If QueryCondition.Keys.Contains("ContainerName") = True Then
                strContainerName = QueryCondition("ContainerName").ToString()
            End If
            strProductName = ""
            If QueryCondition.Keys.Contains("ProductName") = True Then
                strProductName = QueryCondition("ProductName").ToString()
            End If
            strProductRev = ""
            If QueryCondition.Keys.Contains("ProductRev") = True Then
                strProductRev = QueryCondition("ProductRev").ToString()
            End If
            strSpecName = ""
            If QueryCondition.Keys.Contains("SpecName") = True Then
                strSpecName = QueryCondition("SpecName").ToString()
            End If
            strSpecRev = ""
            If QueryCondition.Keys.Contains("SpecRev") = True Then
                strSpecRev = QueryCondition("SpecRev").ToString()
            End If

            strSQL = "SELECT DISTINCT Checkpoints.Checkpointsid,  Containerchilds.Containername AS Productno, " & vbCrLf & _
            "        Checkpoints.Checkpointnote, Checkpoints.Inputnum, '' AS CheckPointDisp, CheckPointResult.Checkpointresultname, " & vbCrLf & _
            "        NVL(COUNT(CheckPointResultDetail.Checkpointresultdetailid),0) AS ResultNum" & vbCrLf & _
            "FROM Checkpointgroup" & vbCrLf & _
            "INNER JOIN Product ON Checkpointgroup.Productid = Product.Productid" & vbCrLf & _
            "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
            "INNER JOIN Spec ON Checkpointgroup.Specid = Spec.Specid" & vbCrLf & _
            "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
            "LEFT JOIN Checkpointgroupcheckpoints ON Checkpointgroupcheckpoints.Checkpointgroupid = Checkpointgroup.Checkpointgroupid" & vbCrLf & _
            "INNER JOIN Checkpoints ON Checkpointgroupcheckpoints.Checkpointsid = Checkpoints.Checkpointsid" & vbCrLf & _
            "INNER JOIN Container ON Container.Productid = Checkpointgroup.Productid " & vbCrLf & _
            "LEFT JOIN Container Containerchilds ON Container.Containerid = Containerchilds.Parentcontainerid  " & vbCrLf & _
            "INNER JOIN CheckPointResult ON Container.Containerid = CheckPointResult.Containerid" & vbCrLf & _
            "AND CheckPointResult.Specid = Checkpointgroup.Specid" & vbCrLf & _
            "INNER JOIN Checkpointresultcheckpointresu ON Checkpointresultcheckpointresu.Checkpointresultid = CheckPointResult.Checkpointresultid" & vbCrLf & _
            "INNER JOIN CheckPointResultDetail ON CheckPointResultDetail.Checkpointresultdetailid = Checkpointresultcheckpointresu.Checkpointresultdetailid" & vbCrLf & _
            "AND CheckPointResultDetail.Productno =  Containerchilds.Containername" & vbCrLf & _
            "WHERE Container.Containername ='" & strContainerName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
            "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
            "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
            "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf & _
            "GROUP BY Checkpoints.Checkpointsid,  Containerchilds.Containername, Checkpoints.Checkpointnote, Checkpoints.Inputnum, " & vbCrLf & _
            "CheckPointResult.Checkpointresultid, CheckPointResult.Checkpointresultname " & vbCrLf & _
            "ORDER BY Containerchilds.Containername, Checkpoints.Checkpointsid" & vbCrLf

            Dim dtMain As DataTable = dal.GetCheckPointInfoForCheck(strSQL)

            Dim strCheckpointresultname As String = ""
            If dtMain.Rows.Count > 0 Then
                If dtMain.Rows(0).IsNull("Checkpointresultname") = False Then
                    strCheckpointresultname = dtMain.Rows(0).Item("Checkpointresultname")
                End If
            End If

            strSQL = "SELECT CheckPointResultDetail.Checkpoints AS Checkpointsid, " & vbCrLf & _
            "        CheckPointResultDetail.Productno, CheckPointResultDetail.Inputindex,  CheckPointResultDetail.Workerresultinfo," & vbCrLf & _
            "       Employee.Fullname AS WorkerFullName, TO_CHAR(CheckPointResultDetail.Submitworkerdate,'RRRR-MM-DD HH24:MI:SS') AS Submitworkerdate, CheckPointResultDetail.Checkerresultinfo, " & vbCrLf & _
            "       Checker.Fullname AS CheckerFullName, TO_CHAR(CheckPointResultDetail.Submitcheckerdate,'RRRR-MM-DD HH24:MI:SS') AS Submitcheckerdate, '' AS EditType," & vbCrLf & _
            "       Employee.Employeename AS WorkerName, Checker.Employeename AS CheckerName, CheckPointResultDetail.Workerdocurl, CheckPointResultDetail.Checkerdocurl" & vbCrLf & _
            "FROM Container" & vbCrLf & _
            "INNER JOIN CheckPointResult ON Container.Containerid = CheckPointResult.Containerid" & vbCrLf & _
            "INNER JOIN Checkpointresultcheckpointresu ON Checkpointresultcheckpointresu.Checkpointresultid = CheckPointResult.Checkpointresultid" & vbCrLf & _
            "INNER JOIN CheckPointResultDetail ON CheckPointResultDetail.Checkpointresultdetailid = Checkpointresultcheckpointresu.Checkpointresultdetailid" & vbCrLf & _
            "INNER JOIN Product ON Container.Productid = Product.Productid" & vbCrLf & _
            "INNER JOIN Productbase ON Productbase.Productbaseid = Product.Productbaseid" & vbCrLf & _
            "INNER JOIN Spec ON CheckPointResult.Specid = Spec.Specid" & vbCrLf & _
            "INNER JOIN Specbase ON Specbase.Specbaseid = Spec.Specbaseid" & vbCrLf & _
            "LEFT JOIN Employee ON Employee.Employeeid =  CheckPointResultDetail.Submitworkerid " & vbCrLf & _
            "LEFT JOIN Employee Checker ON Checker.Employeeid =  CheckPointResultDetail.Submitcheckerid" & vbCrLf & _
            "INNER JOIN Checkpoints ON Checkpoints.Checkpointsid = CheckPointResultDetail.Checkpoints " & vbCrLf & _
            "INNER JOIN CheckPointGroupCheckPoints ON CheckPointGroupCheckPoints.Checkpointsid = Checkpoints.Checkpointsid " & vbCrLf & _
            "INNER JOIN Checkpointgroup ON Checkpointgroup.Checkpointgroupid = CheckPointGroupCheckPoints.Checkpointgroupid " & vbCrLf & _
            "WHERE Container.Containername ='" & strContainerName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strProductRev & "',-1) AND Productbase.Revofrcdid = Product.Productid )" & vbCrLf & _
            "OR  (Product.Productrevision = '" & strProductRev & "'))" & vbCrLf & _
            "AND Specbase.Specname = '" & strSpecName & "'" & vbCrLf & _
            "AND (( NVL('',-1) = NVL('" & strSpecRev & "',-1) AND Specbase.Revofrcdid = Spec.Specid )" & vbCrLf & _
            "OR  (Spec.Specrevision = '" & strSpecRev & "'))" & vbCrLf & _
            "AND CheckPointResult.Checkpointresultname = '" & strCheckpointresultname & "'" & vbCrLf

            Dim dtResult As DataTable = dal.GetCheckPointResult(strSQL)

            For i = 0 To dtMain.Rows.Count - 1
                Dim strCheckpointsid, strProductNo, strInputnum As String
                strCheckpointsid = dtMain.Rows(i).Item("Checkpointsid")
                strProductNo = dtMain.Rows(i).Item("ProductNo")
                strInputnum = dtMain.Rows(i).Item("Inputnum")

                Dim drs As DataRow()
                drs = dtResult.Select("Checkpointsid = '" & strCheckpointsid & "' AND ProductNo = '" & strProductNo & "'")
                If drs.Length = 0 Then
                    If IsNumeric(strInputnum) = True Then
                        Dim intInputnum As Integer
                        intInputnum = CInt(strInputnum)
                        If intInputnum > 0 Then
                            For j = 1 To intInputnum
                                Dim dr As DataRow
                                dr = dtResult.NewRow
                                dr("Checkpointsid") = strCheckpointsid
                                dr("ProductNo") = strProductNo
                                dr("Inputindex") = j
                                dr("EditType") = "add"
                                dtResult.Rows.Add(dr)
                            Next
                        End If
                    End If
                End If
            Next

            Dim ds As New DataSet
            ds.Tables.Add(dtMain.Copy())
            ds.Tables(0).TableName = "dtMain"
            ds.Tables.Add(dtResult.Copy())
            ds.Tables(1).TableName = "dtResult"

            Dim parentColunms = New DataColumn(1) {ds.Tables(0).Columns("Checkpointsid"), ds.Tables(0).Columns("Productno")}
            Dim childColunms = New DataColumn(1) {ds.Tables(1).Columns("Checkpointsid"), ds.Tables(1).Columns("Productno")}
            ds.Relations.Add("rs0", parentColunms, childColunms)

            oResult.DBDataSet = ds
            oResult.Result = True
            Return oResult
        Catch ex As Exception
            oResult.Result = False
            oResult.Message = ex.Message
            Return oResult
        End Try
    End Function

    Function boolCheckNameExists(ByVal strproductid As String, ByVal strSepcid As String, ByVal strCheckName As String) As Boolean Implements uMESCheckPointManageIBusiness.boolCheckNameExists
        Dim strsql As String =
            String.Format("SELECT * FROM stepcheckpoint sc WHERE sc.productid ='{0}' and  sc.specid='{1}' and sc.name='{2}' ", strproductid, strSepcid, strSepcid)
        Dim dt As DataTable = dal.GetCheckTempInfo(strsql)
        If dt.Rows.Count = 0 Then
            boolCheckNameExists = False
        Else
            boolCheckNameExists = True
        End If
    End Function

    Private Function InsertIntoStepCheckPointTable(ByVal checkinputtype As String, ByVal checkno As String, ByVal checkpointnote As String, ByVal checktype As String, ByVal inputnum As String, ByVal keycheck As String,
            ByVal meopcheck As String, ByVal NAME As String, ByVal productid As String, ByVal qualitycheck As String, ByVal stepcheckpointid As String, ByVal workflowstepid As String, ByVal specid As String) As Boolean Implements uMESCheckPointManageIBusiness.InsertIntoStepCheckPointTable


        Dim sql As String =
                        <string>
                         INSERT INTO STEPCHECKPOINT
                                                (CHECKINPUTTYPE,
                                                 CHECKNO,
                                                 CHECKPOINTNOTE,
                                                 CHECKTYPE,
                                                 INPUTNUM,
                                                 KEYCHECK,
                                                 MEOPCHECK,
                                                 NAME,
                                                 PRODUCTID,
                                                 QUALITYCHECK,
                                                 STEPCHECKPOINTID,
                                                 WORKFLOWSTEPID,specid,intime)
                                              VALUES(
                        </string>
        sql += String.Format("'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',sysdate)", checkinputtype, checkno, checkpointnote, checktype, inputnum, keycheck, meopcheck, NAME, productid, qualitycheck, stepcheckpointid, workflowstepid, specid)
        dal.ExecuteSql(sql)

        InsertIntoStepCheckPointTable = True
    End Function



    Private Function GetProductId(ByVal strProduct As String, ByVal strProductVersion As String) As String Implements uMESCheckPointManageIBusiness.GetProductId

        Dim sql As String = String.Format(" select productid from product p inner join productbase pb ON p.productbaseid=pb.productbaseid")
        sql += String.Format(" WHERE p.productrevision='{0}' AND pb.productname='{1}'", strProductVersion, strProduct)
        Dim dt As DataTable = dal.GetCheckTempInfo(sql)
        If dt.Rows.Count = 0 Then
            GetProductId = ""
        Else
            GetProductId = dt.Rows(0)(0).ToString()
        End If
    End Function

    Private Function GetSpecId(ByVal strSpecName As String, ByVal strSpecVersion As String) As String Implements uMESCheckPointManageIBusiness.GetSpecId

        Dim sql As String = String.Format(" select specid from spec s inner join specbase sb ON s.specbaseid=sb.specbaseid")
        sql += String.Format(" WHERE s.specrevision='{0}' AND sb.specname='{1}'", strSpecVersion, strSpecName)

        Dim dt As DataTable = dal.GetCheckTempInfo(sql)
        If dt.Rows.Count = 0 Then
            GetSpecId = ""
        Else
            GetSpecId = dt.Rows(0)(0).ToString()
        End If

    End Function

    Private Function GetWorkflowstepId(ByVal strSpecName As String, ByVal strSpecVersion As String, ByVal strProduct As String, ByVal strProductVersion As String) As String Implements uMESCheckPointManageIBusiness.GetWorkflowstepId
        Dim sql As String =
                    <string>
                            Select WFS.WORKFLOWSTEPID
                                FROM PRODUCT P
                                INNER JOIN PRODUCTBASE PB
                                    ON P.PRODUCTBASEID = PB.PRODUCTBASEID
                                LEFT JOIN WORKFLOW WF
                                    ON P.WORKFLOWID = WF.WORKFLOWID
                                INNER JOIN WORKFLOWSTEP WFS
                                    ON WF.WORKFLOWID = WFS.WORKFLOWID
                                INNER JOIN SPECBASE SB
                                    ON (WFS.SPECBASEID = SB.SPECBASEID OR WFS.SPECID = SB.REVOFRCDID)
                                INNER JOIN SPEC S
                                    ON SB.SPECBASEID = S.SPECBASEID                       
                   </string>
        sql += String.Format(" WHERE PB.PRODUCTNAME = '{0}' AND P.PRODUCTREVISION = '{1}' AND SB.SPECNAME ='{2}'  AND S.SPECREVISION='{3}'", strProduct, strProductVersion, strSpecName, strSpecVersion)

        Dim dt As DataTable = dal.GetCheckTempInfo(sql)
        If dt.Rows.Count = 0 Then
            GetWorkflowstepId = ""
        Else
            GetWorkflowstepId = dt.Rows(0)(0).ToString()
        End If
    End Function




End Class

